package com.ljb.designpatterns;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.ljb.designpatterns.abstractfactory.CPU;
import com.ljb.designpatterns.abstractfactory.HPComputerFactory;
import com.ljb.designpatterns.abstractfactory.LenovoComputerFactory;
import com.ljb.designpatterns.factorymethod.Product;
import com.ljb.designpatterns.factorymethod.ProductAFactory;
import com.ljb.designpatterns.factorymethod.ProductBFactory;
import com.ljb.designpatterns.simplefactory.ProductFactory;
import com.ljb.designpatterns.singleton.SingleA;
import com.ljb.designpatterns.singleton.SingleB;

import org.greenrobot.eventbus.EventBus;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    /**
     * 简单工厂/静态工厂方法模式
     * 优点:代码解耦
     * 缺点:违背了开闭原则
     * 应用场景:生成复杂对象时,确定只有一个工厂类
     */
    private void testSimpleFactory() {
        ProductFactory.create("A").show();
    }

    /**
     * 工厂方法模式
     * 优点:开闭原则,单一职责原则
     * 缺点:增加复杂度
     * 应用场景:于生成复杂对象时,需要有多个工厂类
     * ThreadFactory和Runnable源码实例
     */

    private void testFactoryMethod() {
        new ProductAFactory().create().show();
        new ProductBFactory().create().show();
    }

    /**
     * 抽象工厂模式
     * 优点:代码解耦
     * 缺点:违背了开闭原则
     */
    private void testAbstractFactory() {
        System.out.println("--------------------生产惠普电脑-----------------------");
        new HPComputerFactory().createCPU().showCPU();
        new HPComputerFactory().createMemory().showMemory();

        System.out.println("--------------------生产联想电脑-----------------------");
        new LenovoComputerFactory().createCPU().showCPU();
        new LenovoComputerFactory().createMemory().showMemory();
    }

    /**
     * 单例模式
     * 饿汉式,懒汉式(double check,volatile)
     */
    private void testSingleton() {
        SingleA instance = SingleA.getInstance();
        EventBus.getDefault();

        SingleB instance1 = SingleB.getInstance();
    }

    /**
     * 建造者模式
     */
    private void testBuilder() {

    }


}



























